﻿
function LoadTwitterSupport(isAuthenticated, connectToTwitterUrl, postbackEventReference) {

    if ($get("IdentityStatus_ctl00_PlaceHolderMain_ctl02") != null &&
        $get("IdentityStatusEdit_ctl00_PlaceHolderMain_ctl02") != null) {
        var identityStatusControl = $get("IdentityStatus_ctl00_PlaceHolderMain_ctl02").parentNode.parentNode;
        var identityStatusEditControl = $get("IdentityStatusEdit_ctl00_PlaceHolderMain_ctl02").childNodes.item(0).childNodes.item(0);

        // Write Twitter Images
        if (isAuthenticated.toLowerCase() == "true") {
            identityStatusControl.innerHTML += "<div><img src='/_layouts/motion10.SharePoint.TwitterSupport/twitter_logo.png' border='0' Id='imgTwitterConnected' alt='Connected!' style='height:40px;position:absolute;right:0;top:0;z-index:30;'/></div>";
        }
        else {
            identityStatusControl.innerHTML += "<div><a href='" + connectToTwitterUrl + "'><img src='/_layouts/motion10.SharePoint.TwitterSupport/twitter-connect-button.png' border='0' alt='Connect to Twitter!' style='height:40px;position:absolute;right:0;top:0;z-index:31;' /></a></div>";
        }

        // Attach the Callback Event Reference
        $get("IdentityStatusEdit_ctl00_PlaceHolderMain_ctl02").childNodes.item(0).childNodes.item(0).attachEvent('onblur', function () { TwitterStatusUpdate(postbackEventReference) });

    }


}

// TwitterStatusUpdate: the postback
function TwitterStatusUpdate(postbackEventReference) {
    var arg = $get("IdentityStatusEdit_ctl00_PlaceHolderMain_ctl02").childNodes.item(0).childNodes.item(0).value;
    var context =$get("IdentityStatusEdit_ctl00_PlaceHolderMain_ctl02").childNodes.item(0).childNodes.item(0).value;
    eval(postbackEventReference);
}

// TwitterRefreshNotes: the result
function TwitterRefreshNotes()
{
    $get('imgTwitterConnected').src = '/_layouts/motion10.SharePoint.TwitterSupport/twitter_logo_usd.png';
    setTimeout("$get('imgTwitterConnected').src = '/_layouts/motion10.SharePoint.TwitterSupport/twitter_logo.png';", 1000);
}
